package com.mingte.manghe.config;

import com.mingte.manghe.annotation.LoginRequired;
import com.mingte.manghe.interceptory.JwtInterceptor;
import com.mingte.manghe.interceptory.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ：luxinsheng
 * @Email ：282860642@qq.com
 * @date ：Created in 2021/12/21 10:41
 * @description：配置静态资源访问
 * @modified By：
 * @version: $
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getLoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/**/login")
                //.addPathPatterns("/attachments/**","/folder/**");
                .excludePathPatterns("/api/v1/execl/**","/code");
    }

    @Bean
    public LoginInterceptor getLoginInterceptor() {
        return  new LoginInterceptor();
    }


    //添加放行静态资源
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //文件磁盘图片url 映射
        //配置server虚拟路径，handler为前台访问的目录，locations为files相对应的本地路径
        registry.addResourceHandler("/attachments/**").addResourceLocations("file:E:/格格秀PRD/");
        registry.addResourceHandler("/folder/**").addResourceLocations("file:E:/格格秀DOC/temp/");
        //配置静态文件路径，与上面并不冲突
        //registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/");
    }
}
